<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<!--商家仓库-->
<body>
<a th:href="@{/toAddWareHouse}">上传商品</a>
<a th:href="@{/toForbid}">被封禁的商品</a>
<form th:action="@{/warehouseSearch}" method="get">
    <input type="text" name="search" placeholder="请输入搜索内容">
    <input type="submit" value="搜索">
</form>
<table id="dataTable">
    <thead>
    <th>图片</th>
    <th>商品</th>
    <th>价格</th>
    <th>库存</th>
    </thead>
    <tbody>
    <tr th:each="warehouse : ${warehouses}">
        <td><img style="width:700px;height:500px"
                th:src="@{'/photo/'+${warehouse.avatar}}">
        </td>
        <td th:text="${warehouse.goodsName}"></td>
        <td th:text="${warehouse.goodsPrice}"></td>
        <td th:text="${warehouse.sum}"></td>
        <td>
            <a @click="addGoods" th:href="@{'/addGoods/'+${warehouse.warehouseId}}">上架</a>
            <a @click="deleteWareHouse" th:href="@{'/deleteWareHouse/'+${warehouse.warehouseId}}">删除</a>
            <a th:href="@{'/toScheduledTasks/'+${warehouse.warehouseId}}">定时上架</a>
        </td>
    </tr>
    </tbody>
</table>
<script type="text/javascript" th:src="@{/static/js/vue.js}"></script>
<script type="text/javascript" th:src="@{/static/js/axios.min.js}"></script>
<script type="text/javascript">
    var vue = new Vue({
        el: "#dataTable",
        methods: {
            addGoods: function (event) {
                event.preventDefault();
                axios({
                    method:"post",
                    url:event.target.href,
                }).then(function (response) {
                    alert(response.data);
                    window.location.href = "/toWareHouse";
                });
            },
            deleteWareHouse: function (event) {
                event.preventDefault();
                let msg = "您确定要下架商品吗";
                if (confirm(msg) == true) {
                    axios({
                        method:"delete",
                        url:event.target.href,
                    }).then(function (response) {
                        alert(response.data);
                        window.location.href = "/toWareHouse";
                    });
                }
            }
        }
    });

</script>
</body>
</html>